﻿Imports CapaLogica.CL.UtilidadesGenerales
Imports CapaLogica.CL.Usuario

Module Common

    Sub cambiarElementosDeListas(ByRef plistaOrigen As ListBox, ByRef plistaDestino As ListBox)
        For n = 0 To plistaOrigen.SelectedItems.Count - 1
            plistaDestino.Items.Add(plistaOrigen.SelectedItems.Item(n))
        Next

        For n = 0 To plistaOrigen.SelectedItems.Count - 1
            plistaOrigen.Items.Remove(plistaOrigen.SelectedItems.Item(0))
        Next
    End Sub



    Sub llenarLista(ByRef plisBox As ListBox, ByRef list As List(Of Informacion))

        If list.Count > 0 Then
            limpiarListBox(plisBox)
            Dim temp As Informacion
            Dim i As Integer
            For i = 0 To list.Count - 1
                temp = list(i)
                plisBox.Items.Add(temp)
            Next i

            plisBox.DisplayMember = "Informacion"
            plisBox.ValueMember = "IdInfo"
        End If

    End Sub

    Sub setearLista(ByRef plisBox As ListBox)
        plisBox.DisplayMember = "Informacion"
        plisBox.ValueMember = "IdInfo"
    End Sub

    Sub seterarComboBox(ByRef pComboBox As ComboBox)
        pComboBox.DisplayMember = "Informacion"
        pComboBox.ValueMember = "IdInfo"
    End Sub


    Sub llenarComoBox(ByRef pcomoBox As ComboBox, ByRef list As List(Of Informacion), ByRef fila1 As String)
        limpiarComboBox(pcomoBox)
        pcomoBox.Items.Add(fila1)

        Dim temp As Informacion
        Dim i As Integer
        For i = 0 To list.Count - 1
            temp = list(i)
            pcomoBox.Items.Add(temp)
        Next i

        pcomoBox.DisplayMember = "Informacion"
        pcomoBox.ValueMember = "IdInfo"
        pcomoBox.SelectedIndex = 0
    End Sub


    Function obtenerIdComboBox(ByRef comboBox As ComboBox) As Integer
        Dim id As Informacion

        id = CType(comboBox.SelectedItem, Informacion)
        Return id.IdInfo
    End Function


    Function obtenerIdsDeListBox(ByRef plisBox As ListBox) As List(Of Integer)
        Dim i As Integer
        Dim listaIds As List(Of Integer) = New List(Of Integer)
        Dim temp As Informacion
        For i = 0 To plisBox.Items.Count - 1
            temp = CType(plisBox.Items(i), Informacion)          
            listaIds.Add(Val(temp.IdInfo))
        Next i

        Return listaIds
    End Function


    Public Sub limpiarListBox(ByRef pList As ListBox)
        For n = 0 To pList.Items.Count - 1
            pList.Items.RemoveAt(0)
        Next
    End Sub


    Public Sub limpiarComboBox(ByRef pCombo As ComboBox)
        For i = 0 To pCombo.Items.Count - 1
            pCombo.Items.RemoveAt(0)
        Next
    End Sub



    Public Sub permisosUsuario(ByRef inicio As frm_inicio)
        Dim rol As Integer = Session.Rol

        Select Case rol
            Case 1
                Throw New Exception("Los estudiantes no pueden ingresar a la aplicación local.")

            Case 2

                inicio.tsmUsuariosTool.Visible = False
                inicio.tsmCarreras.Visible = False
                inicio.tsmCursos.Visible = False
                inicio.tsmGrupos.Visible = False
                inicio.tsmEstudiante.Visible = False
                inicio.tsmBlogsTool.Visible = False
                inicio.tsmTemas.Visible = False
                inicio.tsmPeriodoLectivo.Visible = False
                inicio.BitácoraToolStripMenuItem.Visible = False


            Case 3
                inicio.tsmCargaMasivaCursos.Visible = False
                inicio.tsmCargaMasivaEstudiantes.Visible = False
                inicio.tsmMatricular.Visible = False

            Case 4

                inicio.BitácoraToolStripMenuItem.Visible = False
                inicio.tsmGrupos.Visible = False
                inicio.tsmForosTool.Visible = False
                inicio.tsmBlogsTool.Visible = False
                inicio.tsmTemas.Visible = False
                inicio.tsmPeriodoLectivo.Visible = False

            Case 5
                inicio.tsmIngresarUsuario.Visible = False
                inicio.tsmIngresarCarrera.Visible = False
                inicio.tsmIngresarCursos.Visible = False
                inicio.tsmIngresarGrupo.Visible = False
                inicio.tsmEstudiante.Visible = False
                inicio.tsmCargaMasivaCursos.Visible = False
                inicio.tsmBlogsTool.Visible = False
                inicio.tsmForosTool.Visible = False
                inicio.tsmPeriodoLectivo.Visible = False


        End Select
    End Sub

    Public Sub eliminarElementosRepetidos(ByRef noSeleccionados As ListBox, ByRef seleccionados As ListBox)
        Dim tempNoSelec As Informacion
        Dim tempSelec As Informacion
        Dim i As Integer = 0
        Dim e As Integer = 0

        Dim cantNS As Integer = noSeleccionados.Items.Count
        Dim cantS As Integer = seleccionados.Items.Count

        While i < cantNS
            tempNoSelec = CType(noSeleccionados.Items(i), Informacion)

            While e < cantS
                tempSelec = CType(seleccionados.Items(e), Informacion)
                If tempNoSelec.IdInfo = tempSelec.IdInfo Then
                    noSeleccionados.Items.RemoveAt(i)
                    cantNS = cantNS - 1
                    e = cantS
                    i = i - 1
                End If
                e = e + 1
            End While
            e = 0
            i = i + 1
        End While
    End Sub


End Module
